package fpzhan.plane.program.util;

import fpzhan.plane.program.constant.FlowDefine;

import java.util.Set;

public class SetUtils {

    public static int compare(Set<String> set, Set<String>  keys){

        String [] sets = set.toArray(new String[set.size()]);
        String [] keySet = set.toArray(new String[keys.size()]);
        if (set.size()<keys.size()){
            return FlowDefine.LOSE;
        }else if(set.size()>keySet.length){
            return FlowDefine.MORE;
        }else{
            for (int i=0;i<set.size();i++){
                if (keySet[i]==null || sets[i]==null || !keySet[i].equals(sets[i])) {
                    return FlowDefine.FALSE;
                }
            }
            return FlowDefine.TRUE;
        }
    }

    public static boolean equals (Set<String> set1,Set<String> set2){
        String [] set1s = (String []) set1.toArray();
        String [] set2s = (String [] )set2.toArray();
        if(set1s.length==set2s.length){
            for (int i=0;i< set1s.length;i++){
                if (set1s[i]==null || set2s[i]==null || !set1s[i].equals(set2s[i])){
                    return false;
                }
            }
            return true;
        }
        return false;
    }

    public static boolean unEquals (Set<String> set1,Set<String> set2){
        return !equals(set1,set2);
    }

    public static boolean isEmpty(Set set){
        if(set==null || set.isEmpty()){
            return true;
        }
        return false;
    }

    public static boolean isNotEmpty(Set set){
        return !isEmpty(set);
    }
}
